﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

public partial class BaseData_ProductList : System.Web.UI.Page
{
    
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }

    private bool IsUseColorSize
    {
        get
        {
            return new BLL.SYSPARAM().GetProductUpDownColorSizeConfig();
        }
    }

    private bool IsRestockUseColorSize
    {
        get
        {
            return new BLL.SYSPARAM().GetRestockColorSizeConfig();
        }
    }

    public string spdm = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("200300100");
        if (!IsPostBack)
        {
            //属性
            Model.SYSPARAM syspa = new BLL.SYSPARAM().GetModel("002");
            lbStyle.Text = (syspa.SP_PARAM13 == null ? "扩展属性1" : syspa.SP_PARAM13);
            lbSX2.Text = (syspa.SP_PARAM14 == null ? "扩展属性2" : syspa.SP_PARAM14);
            lbSX3.Text = (syspa.SP_PARAM15 == null ? "扩展属性3" : syspa.SP_PARAM15);
            lbSX4.Text = (syspa.SP_PARAM16 == null ? "扩展属性4" : syspa.SP_PARAM16);
            lbSX5.Text = (syspa.SP_PARAM17 == null ? "扩展属性5" : syspa.SP_PARAM17);
            lbSX6.Text = (syspa.SP_PARAM18 == null ? "扩展属性6" : syspa.SP_PARAM18);
            List<Model.AUTOPROP1> a1 = new BLL.AUTOPROP1().GetAllList();
            SXStyle.DataSource = a1;
            SXStyle.DataBind();
            List<Model.AUTOPROP2> a2 = new BLL.AUTOPROP2().GetAllList();
            SX2.DataSource = a2;
            SX2.DataBind();
            List<Model.AUTOPROP3> a3 = new BLL.AUTOPROP3().GetAllList();
            SX3.DataSource = a3;
            SX3.DataBind();
            List<Model.AUTOPROP4> a4 = new BLL.AUTOPROP4().GetAllList();
            SX4.DataSource = a4;
            SX4.DataBind();
            List<Model.AUTOPROP5> a5 = new BLL.AUTOPROP5().GetAllList();
            SX5.DataSource = a5;
            SX5.DataBind();
            List<Model.AUTOPROP6> a6 = new BLL.AUTOPROP6().GetAllList();
            SX6.DataSource = a6;
            SX6.DataBind();
            //商品属性
            List<Model.FJSX1> f1 = new BLL.FJSX1().GetAllList();
            SPType.DataSource = f1;
            SPType.DataBind();

            List<Model.FJSX2> f2 = new BLL.FJSX2().GetAllList();
            SPSX2.DataSource = f2;
            SPSX2.DataBind();

            List<Model.FJSX3> f3 = new BLL.FJSX3().GetAllList();
            SPSX3.DataSource = f3;
            SPSX3.DataBind();

            List<Model.FJSX4> f4 = new BLL.FJSX4().GetAllList();
            SPSX4.DataSource = f4;
            SPSX4.DataBind();

            List<Model.FJSX5> f5 = new BLL.FJSX5().GetAllList();
            SPSX5.DataSource = f5;
            SPSX5.DataBind();

            List<Model.FJSX6> f6 = new BLL.FJSX6().GetAllList();
            SPSX6.DataSource = f6;
            SPSX6.DataBind();

            DropDownList1.SelectedValue = Request.QueryString["type"] == null ? "0" : Request.QueryString["type"].ToString();

            //dropUp.SelectedValue = Request.QueryString["up"] == null ? "-1" : Request.QueryString["up"].ToString();
            //dropPreUp.SelectedValue = Request.QueryString["preup"] == null ? "-1" : Request.QueryString["preup"].ToString();
            dropRecommend.SelectedValue = Request.QueryString["RCMD"] == null ? "-1" : Request.QueryString["RCMD"].ToString();
            dropPromotion.SelectedValue = Request.QueryString["OFFER"] == null ? "-1" : Request.QueryString["OFFER"].ToString();
            dropPresent.SelectedValue = Request.QueryString["GIFT"] == null ? "-1" : Request.QueryString["GIFT"].ToString();
            dropNew.SelectedValue = Request.QueryString["NEW"] == null ? "-1" : Request.QueryString["NEW"].ToString();
            SPType.SelectedValue = Request.QueryString["SPType"] == null ? "000" : Request.QueryString["SPType"].ToString();
            SPSX2.SelectedValue = Request.QueryString["SPSX2"] == null ? "000" : Request.QueryString["SPSX2"].ToString();
            SPSX3.SelectedValue = Request.QueryString["SPSX3"] == null ? "000" : Request.QueryString["SPSX3"].ToString();
            SPSX4.SelectedValue = Request.QueryString["SPSX4"] == null ? "000" : Request.QueryString["SPSX4"].ToString();
            SPSX5.SelectedValue = Request.QueryString["SPSX5"] == null ? "000" : Request.QueryString["SPSX5"].ToString();
            SPSX6.SelectedValue = Request.QueryString["SPSX6"] == null ? "000" : Request.QueryString["SPSX6"].ToString();
            SXStyle.SelectedValue = Request.QueryString["SXStyle"] == null ? "000" : Request.QueryString["SXStyle"].ToString();
            SX2.SelectedValue = Request.QueryString["SX2"] == null ? "000" : Request.QueryString["SX2"].ToString();
            SX3.SelectedValue = Request.QueryString["SX3"] == null ? "000" : Request.QueryString["SX3"].ToString();
            SX4.SelectedValue = Request.QueryString["SX4"] == null ? "000" : Request.QueryString["SX4"].ToString();
            SX5.SelectedValue = Request.QueryString["SX5"] == null ? "000" : Request.QueryString["SX5"].ToString();
            SX6.SelectedValue = Request.QueryString["SX6"] == null ? "000" : Request.QueryString["SX6"].ToString();
            txtSJ1.Text = Request.QueryString["SJ1"] == null ? "" : Request.QueryString["SJ1"].ToString();
            txtSJ2.Text = Request.QueryString["SJ2"] == null ? "" : Request.QueryString["SJ2"].ToString();
            txtMS.Text = Request.QueryString["MS"] == null ? "" : Request.QueryString["MS"].ToString();

            TextBox1.Text =Request.QueryString["key"] == null?"":Request.QueryString["key"].ToString();
            Bind();
            if (Request.QueryString["sxpic"] != null)
            {
                MultiView1.ActiveViewIndex = 3;
                Menu1.Items[3].Selected = true;
            }
            if (Share.GetIsDynamic() == "1")
            {                
                Menu1.Items[6].Enabled = true;
                
            }
            else
            {
                Menu1.Items.RemoveAt(6);               
            }


            if (Request.QueryString["commLink"] != null)
            {
                 
                Menu1.Items[9].Selected = true;
                MultiView1.ActiveViewIndex = 10;
            }




            if (this.IsUseColorSize)
            {
                dlistProduct.DataSource = new BLL.ProductUpDown().GetProductByProductId(spdm);
                dlistProduct.DataBind();
                pnlIsUseColorSize.Visible = true;
                pnlIsUseProduct.Visible = false;
            }
            else
            {
                if (spdm != "")
                {
                    DataSet dst = new BLL.ProductUpDown().GetProduct(spdm);
                    chkUp.Checked = Convert.ToBoolean(dst.Tables[0].Rows[0]["IsUp"]);
                    chkPreUp.Checked = Convert.ToBoolean(dst.Tables[0].Rows[0]["IsPreUp"]);
                    Hidden1.Value = dst.Tables[0].Rows[0]["IsPreUp"].ToString();
                    pnlIsUseProduct.Visible = true;
                    pnlIsUseColorSize.Visible = false;
                }
            }

            if (this.IsRestockUseColorSize)
            {
                dlistRestock.DataSource = new BLL.RingNor.ShangPinBL().GetProductByProductId(spdm);
                dlistRestock.DataBind();
                pnlRestockIsUseColor.Visible = true;
                pnlRestockIsUseProduct.Visible = false;
            }
            else
            {
                if (spdm != "")
                {
                    DataSet dst = new BLL.RingNor.ShangPinBL().GetProduct(spdm);
                    CheckBox3.Checked = Convert.ToBoolean(dst.Tables[0].Rows[0]["IsRestock"]);
                    pnlRestockIsUseProduct.Visible = true;
                    pnlRestockIsUseColor.Visible = false;
                }
            }

        }

    }

    private void Bind()
    {
        string StrSql = "";
        if (TextBox1.Text.Trim() != "")
        {
            if (DropDownList1.SelectedValue == "0")
            {
                if (Request.QueryString["fuzzySearch"]!=null)
                {
                    StrSql += " and SPDM='" + TextBox1.Text.Trim() + "' ";
                }
                else
                {
                    StrSql += " and SPDM like '%" + TextBox1.Text.Trim() + "%' ";
                }
               
            }
            else if(DropDownList1.SelectedValue == "1")
            {
                StrSql += " and SPMC like '%" + TextBox1.Text.Trim() + "%' ";
            }
            else if (DropDownList1.SelectedValue == "2")
            {
                StrSql += " and CA_NAME like '%" + TextBox1.Text.Trim() + "%' ";
            }
        }

        //StrSql += dropUp.SelectedIndex == 0 ? "" : " and CA_UP=" + dropUp.SelectedValue + " ";
        //StrSql += dropPreUp.SelectedIndex == 0 ? "" : " and CA_PREPUP=" + dropPreUp.SelectedValue + " ";
        StrSql += dropRecommend.SelectedIndex == 0 ? "" : " and CA_RCMD=" + dropRecommend.SelectedValue + " ";
        StrSql += dropPromotion.SelectedIndex == 0 ? "" : " and CA_OFFER=" + dropPromotion.SelectedValue + " ";
        StrSql += dropPresent.SelectedIndex == 0 ? "" : " and CA_GIFT=" + dropPresent.SelectedValue + " ";
        StrSql += dropNew.SelectedIndex == 0 ? "" : " and CA_NEW=" + dropNew.SelectedValue + " ";
        StrSql += SPType.SelectedIndex == 0 ? "" : " and FJSX1.SXMC LIKE '%" + SPType.SelectedItem.Text + "%' ";
        StrSql += SPSX2.SelectedIndex == 0 ? "" : " and FJSX2.SXMC LIKE '%" + SPSX2.SelectedItem.Text + "%' ";
        StrSql += SPSX3.SelectedIndex ==0 ? "" : " and FJSX3.SXMC LIKE '%" + SPSX3.SelectedItem.Text + "%' ";
        StrSql += SPSX4.SelectedIndex ==0 ? "" : " and FJSX4.SXMC LIKE '%" + SPSX4.SelectedItem.Text + "%' ";
        StrSql += SPSX5.SelectedIndex == 0 ? "" : " and FJSX5.SXMC LIKE '%" + SPSX5.SelectedItem.Text + "%' ";
        StrSql += SPSX6.SelectedIndex == 0 ? "" : " and FJSX6.SXMC LIKE '%" + SPSX6.SelectedItem.Text + "%' ";

        StrSql += SXStyle.SelectedIndex == 0 ? "" : " and AP1_NAME LIKE '%" + SXStyle.SelectedItem.Text + "%' ";
        StrSql += SX2.SelectedIndex == 0 ? "" : " and AP2_NAME LIKE '%" + SX2.SelectedItem.Text + "%' ";
        StrSql += SX3.SelectedIndex == 0 ? "" : " and AP3_NAME LIKE '%" + SX3.SelectedItem.Text + "%' ";
        StrSql += SX4.SelectedIndex == 0 ? "" : " and AP4_NAME LIKE '%" + SX4.SelectedItem.Text + "%' ";
        StrSql += SX5.SelectedIndex == 0 ? "" : " and AP5_NAME LIKE '%" + SX5.SelectedItem.Text + "%' ";
        StrSql += SX6.SelectedIndex == 0 ? "" : " and AP6_NAME LIKE '%" + SX6.SelectedItem.Text + "%' ";


        StrSql += txtSJ1.Text.Length == 0 ? "" : " and BZSJ>=" + txtSJ1.Text.Trim() + " ";
        StrSql += txtSJ2.Text.Length == 0 ? "" : " and BZSJ<=" + txtSJ2.Text.Trim() + " ";


        StrSql += txtMS.Text.Length == 0 ? "" : " and CA_NOTE LIKE '%" + txtMS.Text.Trim() + "%' ";

        int pageCount, rowCount;
        DataSet ds = new BLL.SHANGPIN().GetShangPinList(GetStartIndex(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize), AspNetPager1.PageSize, StrSql, out rowCount);
        SHANGPINListControl1.Bind(ds);
        AspNetPager1.RecordCount = rowCount;
        if (Request.QueryString["key"] != null&&Request.QueryString["ts"] == null)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                spdm = ds.Tables[0].Rows[0]["SPDM"].ToString();
                hd_spdm.Value = spdm;
                SHANGPINModelControl1.Bind(spdm);
                SPGG1_1.Bind(spdm);
                SPGG2_1.Bind(spdm);
                SHANGPINCOMMENTLIST(AspNetPager2.PageSize, AspNetPager2.CurrentPageIndex, spdm);
                SHANGPINPICLIST(AspNetPager3.PageSize, AspNetPager3.CurrentPageIndex, spdm);
                SHANGPINCOLU0MN1.Bind(spdm);
                COMMODITY_AUTO1.Bind(spdm);

                COMMODITY_LINK1.SPDM = spdm;
                COMMODITY_LINK1.Bind(spdm);

            }
        }
        else
        {
            div_info.Visible = false;
        }
    }
    private void SHANGPINCOMMENTLIST(int pagesize,int pageindex,string spdm)
    {
        COMMODITY_EVALListControl1.Bind(pagesize,pageindex, spdm);
        AspNetPager2.RecordCount = COMMODITY_EVALListControl1.count;
    }
    private void SHANGPINPICLIST(int pagesize, int pageindex, string spdm)
    {
        COMMODITY_PICListControl1.Bind(pagesize, pageindex, spdm);
        AspNetPager3.RecordCount = COMMODITY_PICListControl1.count;
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
    protected void AspNetPager2_PageChanged(object sender, EventArgs e)
    {
        SHANGPINCOMMENTLIST(AspNetPager2.PageSize, AspNetPager2.CurrentPageIndex, hd_spdm.Value);
    }
    protected void AspNetPager3_PageChanged(object sender, EventArgs e)
    {
        SHANGPINPICLIST(AspNetPager3.PageSize, AspNetPager3.CurrentPageIndex, hd_spdm.Value);
    }
    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        MultiView1.ActiveViewIndex = Convert.ToInt32(Menu1.SelectedValue);
        switch (Menu1.SelectedValue)
        {
            case "6":                
                TYLX_SHANGPINControl1.Bind(hd_spdm.Value);
                break;
            case "7":
                COMMODITY_AUTO1.SPDM = hd_spdm.Value;
                COMMODITY_AUTO1.SHUXINGBINDER();
                COMMODITY_AUTO1.Bind(hd_spdm.Value);
                break;
            case "10":
                COMMODITY_LINK1.SPDM = hd_spdm.Value;
                break;
        }        
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (txtSJ1.Text.Trim().Length > 0 || txtSJ2.Text.Trim().Length > 0)
        {
            if (!CheckDecimal(txtSJ1.Text.Trim()) || !CheckDecimal(txtSJ2.Text.Trim()))
            {
                Share.Alert(this.Page, "售价输入必须是浮点数"); return;
            }
        }
        string urlstr="?";
        switch (DropDownList1.SelectedValue)
        {
            case "0":
                urlstr += "type=0";
                break;
            case "1":
                urlstr += "type=1";
                break;
            case "2":
                urlstr += "type=2";
                break;
        }
        urlstr += TextBox1.Text.Trim() == "" ? "" : "&key=" + TextBox1.Text.Trim()+"&ts=yes";
        //urlstr += dropUp.SelectedIndex == 0 ? "" : "&up=" + dropUp.SelectedValue;
        //urlstr += dropPreUp.SelectedIndex == 0 ? "" : "&preup=" + dropPreUp.SelectedValue;
        urlstr += dropRecommend.SelectedIndex == 0 ? "" : "&RCMD=" + dropRecommend.SelectedValue;
        urlstr += dropPromotion.SelectedIndex == 0 ? "" : "&OFFER=" + dropPromotion.SelectedValue;
        urlstr += dropPresent.SelectedIndex == 0 ? "" : "&GIFT=" + dropPresent.SelectedValue;
        urlstr += dropNew.SelectedIndex == 0 ? "" : "&NEW=" + dropNew.SelectedValue;
        urlstr += SPType.SelectedIndex == -1 ? "" : "&SPType=" + SPType.SelectedValue;
        urlstr += SPSX2.SelectedIndex == -1 ? "" : "&SPSX2=" + SPSX2.SelectedValue;
        urlstr += SPSX3.SelectedIndex == -1 ? "" : "&SPSX3=" + SPSX3.SelectedValue;
        urlstr += SPSX4.SelectedIndex == -1 ? "" : "&SPSX4=" + SPSX4.SelectedValue;
        urlstr += SPSX5.SelectedIndex == -1 ? "" : "&SPSX5=" + SPSX5.SelectedValue;
        urlstr += SPSX6.SelectedIndex == -1 ? "" : "&SPSX6=" + SPSX6.SelectedValue;
        urlstr += SXStyle.SelectedIndex == -1 ? "" : "&SXStyle=" + SXStyle.SelectedValue;
        urlstr += SX2.SelectedIndex == -1 ? "" : "&SX2=" + SX2.SelectedValue;
        urlstr += SX3.SelectedIndex == -1 ? "" : "&SX3=" + SX3.SelectedValue;
        urlstr += SX4.SelectedIndex == -1 ? "" : "&SX4=" + SX4.SelectedValue;
        urlstr += SX5.SelectedIndex == -1 ? "" : "&SX5=" + SX5.SelectedValue;
        urlstr += SX6.SelectedIndex == -1 ? "" : "&SX6=" + SX6.SelectedValue;
        urlstr += txtSJ1.Text.Trim().Length == 0 ? "" : "&SJ1=" + txtSJ1.Text.Trim();
        urlstr += txtSJ2.Text.Trim().Length == 0 ? "" : "&SJ2=" + txtSJ2.Text.Trim();
        urlstr += txtMS.Text.Trim().Length == 0 ? "" : "&MS=" + txtMS.Text.Trim();


        Response.Redirect("ProductList.aspx" + urlstr);
    }
    private int GetStartIndex(int pageIndex, int pageSize)
    {
        return 1 + (pageIndex - 1) * pageSize;
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300100", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        try
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("delete from ProductUpDown where SPDM='");
            sb.Append(Request.QueryString["key"].ToString());
            sb.Append("'|");

            foreach (DataListItem tempItem in dlistProduct.Items)
            {
                sb.Append("insert into ProductUpDown(SPDM,GG1DM,GG2DM,ISPREUP,ISUP) values('");
                sb.Append(Request.QueryString["key"].ToString());
                sb.Append("','");
                sb.Append(((HtmlInputHidden)tempItem.FindControl("hidColorCode")).Value);
                sb.Append("','");
                sb.Append(((HtmlInputHidden)tempItem.FindControl("hidSizeCode")).Value);
                sb.Append("',");
                sb.Append(((CheckBox)tempItem.FindControl("CheckBox1")).Checked ? 1 : 0);
                sb.Append(",");
                sb.Append(((CheckBox)tempItem.FindControl("CheckBox2")).Checked ? 1 : 0);
                sb.Append(")|");
            }

            string stringSql = sb.ToString();
            char[] charToTrim = new char[] { '|' };
            string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
            if (new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray))
            {
                Share.Alert(this.Page, "保存成功！");
            }
            else
            {
                Share.Alert(this.Page, "保存失败！");
            }
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
    }
    protected void dlistProduct_ItemCommand(object source, DataListCommandEventArgs e)
    {
        
        if (e.CommandName.ToLower() == "check")
        {
            CheckBox chk = (CheckBox)e.Item.FindControl("CheckBox1");
            HtmlInputHidden hidProductUp = (HtmlInputHidden)e.Item.FindControl("hidProductUp");
            if (hidProductUp.Value == "1")
            {
                Share.Alert(this.Page,"该商品已经上架，不能做预上架操作！");
                chk.Checked = ((HtmlInputHidden)e.Item.FindControl("hidIsPreUp")).Value == "1" ? true : false;
                return;
            }

            if (chk.Checked)
            {
                if (new BLL.COMMODITY_PIC().CheckDefaultExists(Request.QueryString["key"].ToString()))
                {
                    Model.SHANGPIN shangpin = new BLL.SHANGPIN().GetModel(Request.QueryString["key"].ToString());
                    if (shangpin.BZSJ > 0)
                    {

                    }
                    else
                    {
                        chk.Checked = false;
                        Share.Alert(this.Page, "该商品单价不大于零,不能预上架!");
                        return;
                    }

                    Model.SYSPARAM param = new BLL.SYSPARAM().GetModel("015");
                    if (param.SP_PARAM1 == 1)
                    {
                        Model.COMMODITY_AUTO ca = new BLL.COMMODITY_AUTO().GetModel(Request.QueryString["key"].ToString());
                        if (ca.CA_WEIGHT > 0)
                        { }
                        else
                        {
                            chk.Checked = false;
                            Share.Alert(this.Page, "该商品重量不大于零,不能预上架!");
                            return;
                        }
                    }
                    if (new BLL.COMMODITY_CT().SP_COMMODITY_CT_GetByCMODCODE(Request.QueryString["key"].ToString()) > 0)
                    {

                    }
                    else
                    {
                        chk.Checked = false;
                        Share.Alert(this.Page, "该商品没有被分类,不能预上架!");
                        return;
                    }
                }
                else
                {
                    chk.Checked = false;
                    Share.Alert(this.Page, "该商品未上传默认图片,不能预上架!");
                    return;

                }
            }
        }
    }
    protected void dlistProduct_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            CheckBox chk = (CheckBox)e.Item.FindControl("CheckBox1");
            Button btn = (Button)e.Item.FindControl("btnCheck");
            chk.Attributes.Add("onclick", btn.ClientID + ".click();");
        }
    }
    protected void chkPreUp_CheckedChanged(object sender, EventArgs e)
    {
        if (chkUp.Checked)
        {
            Share.Alert(this.Page, "该商品已经上架，不能做预上架操作！");
            chkPreUp.Checked = Hidden1.Value == "1" ? true : false;
        }
        if (chkPreUp.Checked)
        {
            if (new BLL.COMMODITY_PIC().CheckDefaultExists(Request.QueryString["key"].ToString()))
            {
                Model.SHANGPIN shangpin = new BLL.SHANGPIN().GetModel(Request.QueryString["key"].ToString());
                if (shangpin.BZSJ > 0)
                {

                }
                else
                {
                    chkPreUp.Checked = false;
                    Share.Alert(this.Page, "该商品单价不大于零,不能预上架!");
                    return;
                }

                Model.SYSPARAM param = new BLL.SYSPARAM().GetModel("015");
                if (param.SP_PARAM1 == 1)
                {
                    Model.COMMODITY_AUTO ca = new BLL.COMMODITY_AUTO().GetModel(Request.QueryString["key"].ToString());
                    if (ca.CA_WEIGHT > 0)
                    { }
                    else
                    {
                        chkPreUp.Checked = false;
                        Share.Alert(this.Page, "该商品重量不大于零,不能预上架!");
                        return;
                    }
                }
                if (new BLL.COMMODITY_CT().SP_COMMODITY_CT_GetByCMODCODE(Request.QueryString["key"].ToString()) > 0)
                {

                }
                else
                {
                    chkPreUp.Checked = false;
                    Share.Alert(this.Page, "该商品没有被分类,不能预上架!");
                    return;
                }
            }
            else
            {
                chkPreUp.Checked = false;
                Share.Alert(this.Page, "该商品未上传默认图片,不能预上架!");
                return;

            }
        }
    }
    protected void btnSubmit1_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300100", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        try
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("delete from ProductUpDown where SPDM='");
            sb.Append(Request.QueryString["key"].ToString());
            sb.Append("'|");


            sb.Append("insert into ProductUpDown(SPDM,GG1DM,GG2DM,ISPREUP,ISUP) values('");
            sb.Append(Request.QueryString["key"].ToString());
            sb.Append("','");
            sb.Append(1);
            sb.Append("','");
            sb.Append(1);
            sb.Append("',");
            sb.Append(chkPreUp.Checked ? 1 : 0);
            sb.Append(",");
            sb.Append(chkUp.Checked ? 1 : 0);
            sb.Append(")|");
            

            string stringSql = sb.ToString();
            char[] charToTrim = new char[] { '|' };
            string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
            if (new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray))
            {
                Share.Alert(this.Page, "保存成功！");
            }
            else
            {
                Share.Alert(this.Page, "保存失败！");
            }
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
    }
    protected void btnRestockSubmit1_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300100", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        try
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("delete from SPRestock where SPDM='");
            sb.Append(Request.QueryString["key"].ToString());
            sb.Append("'|");

            foreach (DataListItem tempItem in dlistRestock.Items)
            {
                sb.Append("insert into SPRestock(SPDM,GG1,GG2,IsRestock) values('");
                sb.Append(Request.QueryString["key"].ToString());
                sb.Append("','");
                sb.Append(((HtmlInputHidden)tempItem.FindControl("hidColorCode")).Value);
                sb.Append("','");
                sb.Append(((HtmlInputHidden)tempItem.FindControl("hidSizeCode")).Value);
                sb.Append("',");
                sb.Append(((CheckBox)tempItem.FindControl("CheckBox2")).Checked ? 1 : 0);
                sb.Append(")|");
            }
            string stringSql = sb.ToString();
            char[] charToTrim = new char[] { '|' };
            string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
            if (new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray))
            {
                Share.Alert(this.Page, "保存成功！");
            }
            else
            {
                Share.Alert(this.Page, "保存失败！");
            }
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
    }
    protected void btnRestockSubmit2_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("200300100", "00017"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        try
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("delete from SpRestock where SPDM='");
            sb.Append(Request.QueryString["key"].ToString());
            sb.Append("'|");

            sb.Append("insert into SPRestock(SPDM,GG1,GG2,ISReStock) values('");
            sb.Append(Request.QueryString["key"].ToString());
            sb.Append("','1','1',");
            sb.Append(CheckBox3.Checked ? 1 : 0);
            sb.Append(")|");

            string stringSql = sb.ToString();
            char[] charToTrim = new char[] { '|' };
            string[] sqlCommandArray = stringSql.TrimEnd(charToTrim).Split(charToTrim);
            if (new SQLServerDAL.ORDERDOC().Deliver(sqlCommandArray))
            {
                Share.Alert(this.Page, "保存成功！");
            }
            else
            {
                Share.Alert(this.Page, "保存失败！");
            }

        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
    }
    private bool CheckDecimal(string str)
    {
        Regex reg = new Regex(@"^(-?\d+)(\.\d+)?$");
        if (reg.IsMatch(str))
        {
            return true;
        }
        return false;
    }
}
